package org.way.iam.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.way.base.dto.PageParam;
import org.way.iam.entity.SysUserEntity;
import org.way.iam.mapper.SysUserMapper;
import org.way.iam.service.ISysUserService;

import javax.annotation.Resource;

@Service
public class SysUserService extends ServiceImpl<SysUserMapper, SysUserEntity> implements ISysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUserEntity getUser(String username) {
        return this.lambdaQuery().eq(SysUserEntity::getUsername,username).one();
    }

    @Override
    public SysUserEntity getUser() {
        Object userId = StpUtil.getLoginId();
        return getById(userId.toString());
    }

    @Override
    public IPage<SysUserEntity> page(PageParam param) {
        return new LambdaQueryChainWrapper<>(sysUserMapper).page(new Page<>(param.getCurrent(),param.getSize()));
    }

}
